package com.cloudm.technician.ui.modules.cloudm_box.machine

import android.view.View
import android.view.ViewGroup
import com.cloudm.technician.R
import com.cloudm.technician.data.model.MachineInfo
import com.cloudm.technician.extensions.inflate
import com.cloudm.technician.ui.base.BaseAdapter
import com.cloudm.technician.ui.base.BaseViewHolder
import kotlinx.android.synthetic.main.item_machine.view.*

/**
 * 作者: wesley
 * 时间: 2017/12/20
 * 描述: 适配器
 */
class MachineAdapter : BaseAdapter<MachineInfo>() {

    override fun onCreateViewHolder(parent: ViewGroup?,
                                    viewType: Int): BaseViewHolder<MachineInfo> {
        return ItemViewHolder(parent?.inflate(R.layout.item_machine))
    }


    private class ItemViewHolder(itemView: View?) : BaseViewHolder<MachineInfo>(itemView) {

        override fun onBind(t: MachineInfo) {
            itemView.itemTvMachineValue.text = t.name ?: t.modelName
            when(t.selected){
                true -> itemView.itemIvDone.visibility = View.VISIBLE
                else -> itemView.itemIvDone.visibility = View.GONE
            }
        }
    }
}